const { categoryModel } = require("../models/category")
const { tagModel } = require("../models/tag")

const constant = require('../constant')

async function initDefaultCategory() {
  const count = await categoryModel.countDocuments()
  // console.log("category count: ", count)
  if (count == 0) {
    console.log('init default category:', constant.DEFAULT_CATEGORYS)
    let categorys = []
    constant.DEFAULT_CATEGORYS.forEach(v => {
      categorys.push({ name: v })
    })
    await categoryModel.insertMany(categorys)
  }
}

async function initDefaultTags() {
  const count = await tagModel.countDocuments()
  // console.log("tag count: ", count)
  if (count == 0) {
    console.log('init default tags:', constant.DEFAULT_TAGS)
    let tags = []
    constant.DEFAULT_TAGS.forEach(v => {
      tags.push({ name: v })
    })
    await tagModel.insertMany(tags)
  }
}

module.exports = {
  initDefaultCategory,
  initDefaultTags
}
